//---------------------------------------------------------------------------


#pragma hdrstop

#include "ClientList.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)
TClientList::TClientList()
{
    m_ActiveSkt = NULL;
}
void TClientList::AddClient(TCustomWinSocket* cltSkt)
{
    m_OnlineSktList.push_back(cltSkt);
   
}
void TClientList::SetActiveSocket(TCustomWinSocket* skt)
{
   m_ActiveSkt = skt;
}
void TClientList::ResetActiveClient()
{
   m_ActiveSkt = NULL;
}
void TClientList::SetActiveSocket(int index)
{
   m_ActiveSkt = m_OnlineSktList.at(index);
}
void TClientList::Clear()
{
    m_OnlineSktList.clear();
    m_ActiveSkt = NULL;
}
void TClientList::DeleteClient(TCustomWinSocket* cltSkt)
{

   //vector<TCustomWinSocket*>::iterator it = m_OnlineClt.begin();
   vector<TCustomWinSocket*>::iterator xx = m_OnlineSktList.begin();
   vector<TCustomWinSocket*>::iterator yy  = m_OnlineSktList.end();
  // vs.erase(std::remove_if(vs.begin(), vs.end(), FindMatchingString(&fs)), vs.end());
   /*
    int count  =  m_OnlineClt.begin();
   for(int i= 0 ;i<count ;i++)
   {
        if(m_OnlineClt[i]== cltSkt)
        {
           m_OnlineClt.erase(it++);
        }

   } */

   for(xx = m_OnlineSktList.begin();xx != yy;)
   {
       if(*xx == cltSkt)
        {
             m_OnlineSktList.erase(xx++);
        }
        else
             ++xx;
   } 
   

}
TCustomWinSocket* TClientList::GetActiveSocket()
{
    return m_ActiveSkt;
}

vector<TCustomWinSocket*> TClientList::Get_OnlineList()
{
    return m_OnlineSktList;
}

TCustomWinSocket* TClientList::operator [] (int pos)
{
   return m_OnlineSktList.at(pos);
}
int  TClientList::ClientCount()
{
    return  m_OnlineSktList.size();
}
